package com.rightrule.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class FieldThreadPoolConfig {


    /**
     * 变量任务拉取线程池
     *
     * @return
     */
    @Bean(name = "fieldTaskExecutor")
    public ThreadPoolTaskExecutor fieldTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(30); // 核心线程数
        executor.setMaxPoolSize(60); // 最大线程数
        executor.setQueueCapacity(120); // 队列容量
        executor.setKeepAliveSeconds(120); // 线程空闲时间
        executor.setThreadNamePrefix("fieldTaskExecutor-"); // 线程名称前缀
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略
        executor.initialize(); // 初始化线程池
        return executor;
    }
}
